﻿package code.main.view.components{
    import com.yy.manager.ToolTipManager;
    import com.yy.manager.base.IToolTip;
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;

    public class ToolTip extends ToolTipBg implements IToolTip {

        private var _showTimer:Timer;
        public var delaytime:int = 0;
        private var _target:Object;
        private var _toolTipString:String = "";
        private var _toolTipDirection:String = "down";
        protected var _toolTipData:Object = null;
        private var _invalid:Boolean = false;

        public function ToolTip(){
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this.width = 100;
            this.height = 40;
            this.visible = false;
            this.delaytime = 0;
        }
        public function show(_arg1:Object, _arg2:String="", _arg3:String="down", _arg4:Object=null):void{
            this._target = _arg1;
            this._toolTipString = _arg2;
            this._toolTipDirection = _arg3;
            this._toolTipData = _arg4;
            if (this._showTimer == null){
                this._showTimer = new Timer(this.delaytime, 1);
                this._showTimer.addEventListener(TimerEvent.TIMER, this.showTimerHandler);
            };
            this._showTimer.reset();
            this._showTimer.start();
        }
        private function showTimerHandler(_arg1:TimerEvent):void{
            this._show(this._target, this._toolTipString, this._toolTipDirection, this._toolTipData);
        }
        protected function _show(_arg1:Object, _arg2:String="", _arg3:String="down", _arg4:Object=null):void{
            var _local5:Point;
            this.direction = _arg3;
            var _local6:DisplayObject = (_arg1 as DisplayObject);
            switch (_arg3){
                case ToolTipManager.DOWN:
                    _local5 = _local6.localToGlobal(new Point((_local6.width / 2), _local6.height));
                    break;
                case ToolTipManager.UP:
                    _local5 = _local6.localToGlobal(new Point((_local6.width / 2), 0));
                    break;
                case ToolTipManager.LEFT:
                    _local5 = _local6.localToGlobal(new Point(_local6.width, (_local6.height / 2)));
                    break;
                case ToolTipManager.RIGHT:
                    _local5 = _local6.localToGlobal(new Point(0, (_local6.height / 2)));
                    break;
            };
            this.x = (_local5.x - this.offsetX);
            this.y = (_local5.y - this.offsetY);
            this.visible = true;
        }
        public function hide():void{
            if (this._showTimer != null){
                this._showTimer.stop();
            };
            this.scaleX = 1;
            this.visible = false;
            this.invalid = true;
        }
        public function get invalid():Boolean{
            return (this._invalid);
        }
        public function set invalid(_arg1:Boolean):void{
            this._invalid = _arg1;
        }

    }
}